package com.gljx.web.controller.JournalController;

import com.gljx.util.GetFid;
import com.gljx.util.TimeFormat;
import com.gljx.web.Entity.*;
import com.gljx.web.Entity.JournalEntry.CarExpenseDetailJournal;
import com.gljx.web.Entity.JournalEntry.lCarRefuelingJournal;
import com.gljx.web.dao.RecordinMapper;
import com.gljx.web.dao.RecordinentryMapper;
import com.gljx.web.dao.StudentMapper;
import com.gljx.web.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/")
public class CarExpenseDetailJournalController {

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private FillingWareRegEntryService fillingWareRegEntryService;

    @Autowired
    private OilspecService oilspecService;

    @Autowired
    private OtherCarAddOilEntryService otherCarAddOilEntryService;

    @Autowired
    private CarRefuelEntryService carRefuelEntryService;
    /**
     * @Author lcx
     * @Date 2017/12/18 0018 上午 9:42
     * 查询加油站进销存统计报表
     */
    @RequestMapping(value = "/chooseCarExpenseDetailJournal")
    public String chooseCarExpenseDetailJournal(HttpServletRequest request) {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");                                   //获取已经登录用户数据
        Department department = departmentService.queryAdminByFid(user.getFcompanyid());   //获取登录用户组织ID
        Calendar cale = Calendar.getInstance();// 得到一个Calendar的实例
        cale.add(Calendar.MONTH, -1);
        cale.set(Calendar.DAY_OF_MONTH, 1);
        Calendar cale2 = Calendar.getInstance();// 得到一个Calendar的实例
        cale2.add(Calendar.MONTH, 0);
        cale2.set(Calendar.DAY_OF_MONTH, 0);
        Date resultDate = cale.getTime(); // 结果
        Date resultDate2 = cale2.getTime(); // 结果
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String beginTime = sdf.format(resultDate);
        String endTime = sdf.format(resultDate2);

        request.setAttribute("company", department);
        request.setAttribute("beginTime", beginTime);
        request.setAttribute("endTime", endTime);

        /*request.setAttribute("beginTime", "2017-06-01");
        request.setAttribute("endTime", "2017-06-30");*/

        return "backHome/journaling/financialJournaling/CarExpenseDetailJournaling/CarExpenseDetailJournalingList";

    }

    /**
     * @Author lcx
     * @Date 2017/12/21 0021 下午 2:37
     * 明细表的加油价格未查询
     */
    @RequestMapping(value = "/selCarExpenseDetailJournal")
    @ResponseBody
    @Transactional
    public Map selCarExpenseDetailJournal(HttpServletRequest request, @RequestParam(defaultValue = "", value = "cfoilspecName") String cfoilspecName,
                                          @RequestParam(defaultValue = "", value = "begindate") String begindate,
                                          @RequestParam(defaultValue = "", value = "enddate") String enddate,
                                          @RequestParam(defaultValue = "", value = "state") String state) {

        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");                                   //获取已经登录用户数据
        Department department = departmentService.queryAdminByFid(user.getFcompanyid());   //获取登录用户组织ID
        //1.查询
        Map returnmap = new HashMap();

        Map map = new HashMap();
        map.put("companyId", department.getFid());
        map.put("beginTime", begindate);
        map.put("endTime", enddate);

        System.out.printf(String.valueOf(System.currentTimeMillis()));
        List<CarExpenseDetailJournal> carExpenseDetailJournalList = carRefuelEntryService.selCarExpenseDetail(map, state);
        System.out.printf(String.valueOf(System.currentTimeMillis()));
        //List<CarExpenseDetailJournal> carExpenseDetailJournalList = new ArrayList<>();
        //carExpenseDetailJournalList.add(new CarExpenseDetailJournal());
        returnmap.put("carExpense", carExpenseDetailJournalList);
        returnmap.put("gsName", department.getFnameL2());

        //查询期末结存

        return returnmap;
    }

}
